home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cocktail / l2r.lha / l2r / Errors.c next >
C/C++ Source or Header  |  1992-08-20  |  3KB  |  92 lines

  1. /************************************************************************/
  2. /*                                    */
  3. /* error handler for l2r                        */
  4. /*                                    */
  5. /************************************************************************/
  6.  
  7. # include "Errors.h"
  8. # include <stdio.h>
  9. # include "Sets.h"
  10.  
  11. # define MissingBrace        9
  12. # define MissingQuote        10
  13. # define MissingDQuote        11
  14. # define UnclosedComment    12
  15.  
  16. static void WriteErrorMessage (ErrorCode, ErrorClass, Position)
  17.    short ErrorCode, ErrorClass;
  18.    tPosition Position;
  19.    {
  20.       (void) fprintf (stderr, "%3d, %2d: ", Position.Line, Position.Column);
  21.  
  22.       switch (ErrorClass) {
  23.       case xxFatal        : (void) fprintf (stderr, "Fatal       "); break;
  24.       case xxRestriction    : (void) fprintf (stderr, "Restriction "); break;
  25.       case xxError        : (void) fprintf (stderr, "Error       "); break;
  26.       case xxWarning        : (void) fprintf (stderr, "Warning     "); break;
  27.       case xxRepair        : (void) fprintf (stderr, "Repair      "); break;
  28.       case xxNote        : (void) fprintf (stderr, "Note        "); break;
  29.       case xxInformation    : (void) fprintf (stderr, "Information "); break;
  30.       default            : (void) fprintf (stderr, "Error class %d ", ErrorClass);
  31.       }
  32.  
  33.       switch (ErrorCode) {
  34.       case xxNoText        : break;
  35.       case xxSyntaxError    : (void) fprintf (stderr, "syntax error"    ); break;
  36.       case xxExpectedTokens    : (void) fprintf (stderr, "expected tokens"    ); break;
  37.       case xxRestartPoint    : (void) fprintf (stderr, "restart point"    ); break;
  38.       case xxTokenInserted    : (void) fprintf (stderr, "token inserted "    ); break;
  39.       case MissingBrace        : (void) fprintf (stderr, "} missing"        ); break;
  40.       case MissingQuote        : (void) fprintf (stderr, "' missing"        ); break;
  41.       case MissingDQuote    : (void) fprintf (stderr, "\" missing"        ); break;
  42.       case UnclosedComment    : (void) fprintf (stderr, "unclosed comment"    ); break;
  43.       default            : (void) fprintf (stderr, "error code %d", ErrorCode);
  44.       }
  45.    }
  46.  
  47. static void WriteInfo (InfoClass, Info)
  48.    short    InfoClass;
  49.    char *    Info;
  50.    {
  51.       if (InfoClass == xxNone) return;
  52.       (void) fprintf (stderr, ": ");
  53.       switch (InfoClass) {
  54.       case xxInteger    : (void) fprintf (stderr, "%d", * (int *)    Info); break;
  55.       case xxShort    : (void) fprintf (stderr, "%d", * (short *)    Info); break;
  56.       case xxSet    : WriteSet     (stderr, (tSet *)        Info); break;
  57.       case xxString    : (void) fprintf (stderr, "%s",            Info); break;
  58.       default        : (void) fprintf (stderr, "info class: %d", InfoClass);
  59.       }
  60.    }
  61.  
  62. void ErrorMessageI
  63. # ifdef __STDC__
  64.    (short ErrorCode, short ErrorClass, tPosition Position, short InfoClass, char * Info)
  65. # else
  66.    (ErrorCode, ErrorClass, Position, InfoClass, Info)
  67.    short    ErrorCode, ErrorClass;
  68.    tPosition    Position;
  69.    short    InfoClass;
  70.    char *    Info;
  71. # endif
  72.    {
  73.       extern void exit ();
  74.  
  75.       WriteErrorMessage (ErrorCode, ErrorClass, Position);
  76.       WriteInfo (InfoClass, Info);
  77.       (void) fprintf (stderr, "\n");
  78.       if (ErrorClass == xxFatal) exit (1);
  79.    }
  80.  
  81. void ErrorMessage
  82. # ifdef __STDC__
  83.    (short ErrorCode, short ErrorClass, tPosition Position)
  84. # else
  85.    (ErrorCode, ErrorClass, Position)
  86.    short    ErrorCode, ErrorClass;
  87.    tPosition    Position;
  88. # endif
  89.    {
  90.       ErrorMessageI (ErrorCode, ErrorClass, Position, xxNone, (char *) NULL);
  91.    }
  92.